import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import common from './modules/common'
import login from './modules/login'
import * as types from './mutation-types'
import { removeServerTime, removeToken } from '@/common/auth' // 获取时间差

Vue.use(Vuex)

const store = new Vuex.Store({
  mutations: {},
  actions: {
    // user logout
    logout({ commit, state }) {
      return new Promise((resolve, reject) => {
        removeServerTime()
        removeToken()
        resolve()
      })
    }
  },
  modules: {
    common,
    login
  },
  // 持久化存储
  plugins: [
    createPersistedState({
      storage: window.localStorage,
			key: "machineVuex",
      paths: ['common', 'login']
    })
  ]
})

export default store
